package Model;
import java.awt.event.ActionListener;
import java.util.Random;

import javax.swing.Timer;

import Config.Constantes;


public class AlienB extends NaveModelInterface implements Constantes {
	static final int speed=1;
	int aux, cambiar, direccion;
	public AlienB(int x, int y) {
		super("a2.png",x,y);
		aux = 0;
		cambiar = aleatorio();
		visible = true;
		direccion = aleatorioConNegativo();
		if(direccion >3 && direccion <9)
			direccion = 1;
		else if(direccion <0)
			direccion = 0;
		else if(direccion > 10 )
			direccion = -1;
		setDy(direccion);
	}
	
	public void posicionar()
	{
		if(this.getX() + getBoundx() < 0)// si sale de la pantalla que regrese
		{
			this.setDx(Constantes.WIDTH + this.getBoundx());

		}
		else
		{
			this.setDx(-1*speed);
					
		}
		
		if(this.getY() + this.getBoundy() < 0) // notocar
		{
			this.setDy(+1);
			//System.out.println("y < heigt, y:  "+this.getY()+"height"+Constantes.HEIGHT );
		}
		else if ( this.getY()  > Constantes.HEIGHT) // no tocar
		{
			this.setDy(-1 );
			//System.out.println(" y > height, y:  "+this.getY()+"height"+Constantes.HEIGHT );
		}
		else if(aux == cambiar)
			{
				this.setDy(cambiarDireccion());
				aux = 0;
			}
		else	
		{	
			this.setDy(this.getDy());
		}
				
				
			
			
		aux++;
		
		this.move();
	}
	protected void move() {
		this.setX(this.getX()+ this.getDx());
		this.setY(this.getY()+ this.getDy());
		//y += dy;
	}
	private int cambiarDireccion()
	{
		if(this.getDy() == 0)
			return 1;
		else if(this.getDy() < 0)
			return 0;
		else return -1;
	}
	private int aleatorio()
	{
		int ale = (int)(Math.random()*300+1);
		return  ale;
		//return r.nextInt();
		
	}
	private int aleatorioConNegativo()
	{
		return (int)((Math.random()*200)-5);
	}
}
